﻿@namespace MudBlazor.UnitTests.TestComponents

<MudDataGrid T="Model" ServerData="@(new Func<GridState<Model>, Task<GridData<Model>>>(ServerReload))">
    <Columns>
        <PropertyColumn Property="x => x.Name" />
        <PropertyColumn Property="x => x.Age" />
        <PropertyColumn Property="x => x.Status" />
    </Columns>
    <PagerContent>
        <MudDataGridPager />
    </PagerContent>
</MudDataGrid>

@code {
    public record Model (string Name, int Age, Severity Status);
    private int _totalItems = 100;
    IEnumerable<Model> _data;

    protected override void OnInitialized()
    {
        List<Model> data = new List<Model>();

        // populate the data
        for (var i = 0; i < 100; i++)
        {
            data.Add(new Model($"Name {i}", i, Severity.Info));
        }

        _data = data;
    }

    private async Task<GridData<Model>> ServerReload(GridState<Model> state)
    {
        var data = _data.OrderBySortDefinitions(state);
        data = data.Skip(state.Page * state.PageSize).Take(state.PageSize);

        return await Task.FromResult(new GridData<Model>() { TotalItems = _totalItems, Items = data });
    }

}
